from django.shortcuts import render, get_object_or_404
from django.http import JsonResponse
from .models import Movie, MovieLink

def index(request):
    # 获取第一个电影作为示例
    movie = Movie.objects.first()
    context = {
        'movie': movie,
        'links': movie.links.all() if movie else []
    }
    return render(request, 'movies/index.html', context)

def get_links(request, movie_id):
    movie = get_object_or_404(Movie, pk=movie_id)
    links = movie.links.all()
    return render(request, 'movies/links_partial.html', {'links': links})
